package yxy.game.pm2.command.yilingbattle;

import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.YiLingMessage;
import yxy.game.pm2.module.yiling.YiLingBattleModule;

/****************************************
 * @name CMD_YiLingBattleReceiveProgress
 * @description 夷陵之战 通关奖励进度
 * @author 梁健彬
 * @since 2022-07-26
 ***************************************/
@MessageType(proto = Command.YiLingBattleReceiveProgress, classtype = YiLingMessage.YiLingBattleReceiveProgressRequest.class)
public class CMD_YiLingBattleReceiveProgress extends Command<YiLingMessage.YiLingBattleReceiveProgressRequest> {

    @Override
    public void execute(MessageSource messageSource, YiLingMessage.YiLingBattleReceiveProgressRequest request) {
        try {
            String playerCode = messageSource.getTag(   );

            YiLingMessage.YiLingBattleReceiveProgressResponse.Builder response = YiLingMessage.YiLingBattleReceiveProgressResponse.newBuilder();

            YiLingBattleModule module = YiLingBattleModule.get(playerCode);
            for (Integer integer : module.getGoThroughReward()) {
                response.addIds(integer);
            }

            send(messageSource, response, Result.Success);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void send(MessageSource messageSource, YiLingMessage.YiLingBattleReceiveProgressResponse.Builder response, Result result) {
        response.setResult(result.packResult());
        MessageEmitterHandler.getInstance().send(messageSource, response.build());
    }
}